<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>asserts.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_testing_asserts.js.html">asserts.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>goog.provide(&#39;goog.testing.JsUnitException&#39;);
<a name="line15"></a>goog.provide(&#39;goog.testing.asserts&#39;);
<a name="line16"></a>
<a name="line17"></a>goog.require(&#39;goog.testing.stacktrace&#39;);
<a name="line18"></a>
<a name="line19"></a>// TODO(user): Copied from JsUnit with some small modifications, we should
<a name="line20"></a>// reimplement the asserters.
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>/**
<a name="line24"></a> * @typedef {Array|NodeList|Arguments|{length: number}}
<a name="line25"></a> */
<a name="line26"></a>goog.testing.asserts.ArrayLike;
<a name="line27"></a>
<a name="line28"></a>var DOUBLE_EQUALITY_PREDICATE = function(var1, var2) {
<a name="line29"></a>  return var1 == var2;
<a name="line30"></a>};
<a name="line31"></a>var JSUNIT_UNDEFINED_VALUE;
<a name="line32"></a>var TO_STRING_EQUALITY_PREDICATE = function(var1, var2) {
<a name="line33"></a>  return var1.toString() === var2.toString();
<a name="line34"></a>};
<a name="line35"></a>
<a name="line36"></a>var PRIMITIVE_EQUALITY_PREDICATES = {
<a name="line37"></a>  &#39;String&#39;: DOUBLE_EQUALITY_PREDICATE,
<a name="line38"></a>  &#39;Number&#39;: DOUBLE_EQUALITY_PREDICATE,
<a name="line39"></a>  &#39;Boolean&#39;: DOUBLE_EQUALITY_PREDICATE,
<a name="line40"></a>  &#39;Date&#39;: function(date1, date2) {
<a name="line41"></a>    return date1.getTime() == date2.getTime();
<a name="line42"></a>  },
<a name="line43"></a>  &#39;RegExp&#39;: TO_STRING_EQUALITY_PREDICATE,
<a name="line44"></a>  &#39;Function&#39;: TO_STRING_EQUALITY_PREDICATE
<a name="line45"></a>};
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * Compares equality of two numbers, allowing them to differ up to a given
<a name="line50"></a> * tolerance.
<a name="line51"></a> * @param {number} var1 A number.
<a name="line52"></a> * @param {number} var2 A number.
<a name="line53"></a> * @param {number} tolerance the maximum allowed difference.
<a name="line54"></a> * @return {boolean} Whether the two variables are sufficiently close.
<a name="line55"></a> * @private
<a name="line56"></a> */
<a name="line57"></a>goog.testing.asserts.numberRoughEqualityPredicate_ = function(
<a name="line58"></a>    var1, var2, tolerance) {
<a name="line59"></a>  return Math.abs(var1 - var2) &lt;= tolerance;
<a name="line60"></a>};
<a name="line61"></a>
<a name="line62"></a>
<a name="line63"></a>/**
<a name="line64"></a> * @type {Object.&lt;string, function(*, *, number): boolean&gt;}
<a name="line65"></a> * @private
<a name="line66"></a> */
<a name="line67"></a>goog.testing.asserts.primitiveRoughEqualityPredicates_ = {
<a name="line68"></a>  &#39;Number&#39;: goog.testing.asserts.numberRoughEqualityPredicate_
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>var _trueTypeOf = function(something) {
<a name="line73"></a>  var result = typeof something;
<a name="line74"></a>  try {
<a name="line75"></a>    switch (result) {
<a name="line76"></a>      case &#39;string&#39;:
<a name="line77"></a>        break;
<a name="line78"></a>      case &#39;boolean&#39;:
<a name="line79"></a>        break;
<a name="line80"></a>      case &#39;number&#39;:
<a name="line81"></a>        break;
<a name="line82"></a>      case &#39;object&#39;:
<a name="line83"></a>        if (something == null) {
<a name="line84"></a>          result = &#39;null&#39;;
<a name="line85"></a>          break;
<a name="line86"></a>        }
<a name="line87"></a>      case &#39;function&#39;:
<a name="line88"></a>        switch (something.constructor) {
<a name="line89"></a>          case new String(&#39;&#39;).constructor:
<a name="line90"></a>            result = &#39;String&#39;;
<a name="line91"></a>            break;
<a name="line92"></a>          case new Boolean(true).constructor:
<a name="line93"></a>            result = &#39;Boolean&#39;;
<a name="line94"></a>            break;
<a name="line95"></a>          case new Number(0).constructor:
<a name="line96"></a>            result = &#39;Number&#39;;
<a name="line97"></a>            break;
<a name="line98"></a>          case new Array().constructor:
<a name="line99"></a>            result = &#39;Array&#39;;
<a name="line100"></a>            break;
<a name="line101"></a>          case new RegExp().constructor:
<a name="line102"></a>            result = &#39;RegExp&#39;;
<a name="line103"></a>            break;
<a name="line104"></a>          case new Date().constructor:
<a name="line105"></a>            result = &#39;Date&#39;;
<a name="line106"></a>            break;
<a name="line107"></a>          case Function:
<a name="line108"></a>            result = &#39;Function&#39;;
<a name="line109"></a>            break;
<a name="line110"></a>          default:
<a name="line111"></a>            var m = something.constructor.toString().match(
<a name="line112"></a>                /function\s*([^( ]+)\(/);
<a name="line113"></a>            if (m) {
<a name="line114"></a>              result = m[1];
<a name="line115"></a>            } else {
<a name="line116"></a>              break;
<a name="line117"></a>            }
<a name="line118"></a>        }
<a name="line119"></a>        break;
<a name="line120"></a>    }
<a name="line121"></a>  } catch (e) {
<a name="line122"></a>
<a name="line123"></a>  } finally {
<a name="line124"></a>    result = result.substr(0, 1).toUpperCase() + result.substr(1);
<a name="line125"></a>  }
<a name="line126"></a>  return result;
<a name="line127"></a>};
<a name="line128"></a>
<a name="line129"></a>var _displayStringForValue = function(aVar) {
<a name="line130"></a>  var result;
<a name="line131"></a>  try {
<a name="line132"></a>    result = &#39;&lt;&#39; + String(aVar) + &#39;&gt;&#39;;
<a name="line133"></a>  } catch (ex) {
<a name="line134"></a>    result = &#39;&lt;toString failed: &#39; + ex.message + &#39;&gt;&#39;;
<a name="line135"></a>    // toString does not work on this object :-(
<a name="line136"></a>  }
<a name="line137"></a>  if (!(aVar === null || aVar === JSUNIT_UNDEFINED_VALUE)) {
<a name="line138"></a>    result += &#39; (&#39; + _trueTypeOf(aVar) + &#39;)&#39;;
<a name="line139"></a>  }
<a name="line140"></a>  return result;
<a name="line141"></a>};
<a name="line142"></a>
<a name="line143"></a>var fail = function(failureMessage) {
<a name="line144"></a>  goog.testing.asserts.raiseException(&#39;Call to fail()&#39;, failureMessage);
<a name="line145"></a>};
<a name="line146"></a>
<a name="line147"></a>var argumentsIncludeComments = function(expectedNumberOfNonCommentArgs, args) {
<a name="line148"></a>  return args.length == expectedNumberOfNonCommentArgs + 1;
<a name="line149"></a>};
<a name="line150"></a>
<a name="line151"></a>var commentArg = function(expectedNumberOfNonCommentArgs, args) {
<a name="line152"></a>  if (argumentsIncludeComments(expectedNumberOfNonCommentArgs, args)) {
<a name="line153"></a>    return args[0];
<a name="line154"></a>  }
<a name="line155"></a>
<a name="line156"></a>  return null;
<a name="line157"></a>};
<a name="line158"></a>
<a name="line159"></a>var nonCommentArg = function(desiredNonCommentArgIndex,
<a name="line160"></a>    expectedNumberOfNonCommentArgs, args) {
<a name="line161"></a>  return argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) ?
<a name="line162"></a>      args[desiredNonCommentArgIndex] :
<a name="line163"></a>      args[desiredNonCommentArgIndex - 1];
<a name="line164"></a>};
<a name="line165"></a>
<a name="line166"></a>var _validateArguments = function(expectedNumberOfNonCommentArgs, args) {
<a name="line167"></a>  var valid = args.length == expectedNumberOfNonCommentArgs ||
<a name="line168"></a>      args.length == expectedNumberOfNonCommentArgs + 1 &amp;&amp;
<a name="line169"></a>      goog.isString(args[0]);
<a name="line170"></a>  _assert(null, valid, &#39;Incorrect arguments passed to assert function&#39;);
<a name="line171"></a>};
<a name="line172"></a>
<a name="line173"></a>var _assert = function(comment, booleanValue, failureMessage) {
<a name="line174"></a>  if (!booleanValue) {
<a name="line175"></a>    goog.testing.asserts.raiseException(comment, failureMessage);
<a name="line176"></a>  }
<a name="line177"></a>};
<a name="line178"></a>
<a name="line179"></a>
<a name="line180"></a>/**
<a name="line181"></a> * @param {*} expected The expected value.
<a name="line182"></a> * @param {*} actual The actual value.
<a name="line183"></a> * @return {string} A failure message of the values don&#39;t match.
<a name="line184"></a> * @private
<a name="line185"></a> */
<a name="line186"></a>goog.testing.asserts.getDefaultErrorMsg_ = function(expected, actual) {
<a name="line187"></a>  var msg = &#39;Expected &#39; + _displayStringForValue(expected) + &#39; but was &#39; +
<a name="line188"></a>      _displayStringForValue(actual);
<a name="line189"></a>  if ((typeof expected == &#39;string&#39;) &amp;&amp; (typeof actual == &#39;string&#39;)) {
<a name="line190"></a>    // Try to find a human-readable difference.
<a name="line191"></a>    var limit = Math.min(expected.length, actual.length);
<a name="line192"></a>    var commonPrefix = 0;
<a name="line193"></a>    while (commonPrefix &lt; limit &amp;&amp;
<a name="line194"></a>        expected.charAt(commonPrefix) == actual.charAt(commonPrefix)) {
<a name="line195"></a>      commonPrefix++;
<a name="line196"></a>    }
<a name="line197"></a>
<a name="line198"></a>    var commonSuffix = 0;
<a name="line199"></a>    while (commonSuffix &lt; limit &amp;&amp;
<a name="line200"></a>        expected.charAt(expected.length - commonSuffix - 1) ==
<a name="line201"></a>            actual.charAt(actual.length - commonSuffix - 1)) {
<a name="line202"></a>      commonSuffix++;
<a name="line203"></a>    }
<a name="line204"></a>
<a name="line205"></a>    if (commonPrefix + commonSuffix &gt; limit) {
<a name="line206"></a>      commonSuffix = 0;
<a name="line207"></a>    }
<a name="line208"></a>
<a name="line209"></a>    if (commonPrefix &gt; 2 || commonSuffix &gt; 2) {
<a name="line210"></a>      var printString = function(str) {
<a name="line211"></a>        var startIndex = Math.max(0, commonPrefix - 2);
<a name="line212"></a>        var endIndex = Math.min(str.length, str.length - (commonSuffix - 2));
<a name="line213"></a>        return (startIndex &gt; 0 ? &#39;...&#39; : &#39;&#39;) +
<a name="line214"></a>            str.substring(startIndex, endIndex) +
<a name="line215"></a>            (endIndex &lt; str.length ? &#39;...&#39; : &#39;&#39;);
<a name="line216"></a>      };
<a name="line217"></a>
<a name="line218"></a>      msg += &#39;\nDifference was at position &#39; + commonPrefix +
<a name="line219"></a>          &#39;. Expected [&#39; + printString(expected) +
<a name="line220"></a>          &#39;] vs. actual [&#39; + printString(actual) + &#39;]&#39;;
<a name="line221"></a>    }
<a name="line222"></a>  }
<a name="line223"></a>  return msg;
<a name="line224"></a>};
<a name="line225"></a>
<a name="line226"></a>
<a name="line227"></a>/**
<a name="line228"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line229"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line230"></a> */
<a name="line231"></a>var assert = function(a, opt_b) {
<a name="line232"></a>  _validateArguments(1, arguments);
<a name="line233"></a>  var comment = commentArg(1, arguments);
<a name="line234"></a>  var booleanValue = nonCommentArg(1, 1, arguments);
<a name="line235"></a>
<a name="line236"></a>  _assert(comment, goog.isBoolean(booleanValue),
<a name="line237"></a>      &#39;Bad argument to assert(boolean)&#39;);
<a name="line238"></a>  _assert(comment, booleanValue, &#39;Call to assert(boolean) with false&#39;);
<a name="line239"></a>};
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/**
<a name="line243"></a> * Asserts that the function throws an error.
<a name="line244"></a> *
<a name="line245"></a> * @param {!(string|Function)} a The assertion comment or the function to call.
<a name="line246"></a> * @param {!Function=} opt_b The function to call (if the first argument of
<a name="line247"></a> *     {@code assertThrows} was the comment).
<a name="line248"></a> * @return {*} The error thrown by the function.
<a name="line249"></a> * @throws {goog.testing.JsUnitException} If the assertion failed.
<a name="line250"></a> */
<a name="line251"></a>var assertThrows = function(a, opt_b) {
<a name="line252"></a>  _validateArguments(1, arguments);
<a name="line253"></a>  var func = nonCommentArg(1, 1, arguments);
<a name="line254"></a>  var comment = commentArg(1, arguments);
<a name="line255"></a>  _assert(comment, typeof func == &#39;function&#39;,
<a name="line256"></a>      &#39;Argument passed to assertThrows is not a function&#39;);
<a name="line257"></a>
<a name="line258"></a>  try {
<a name="line259"></a>    func();
<a name="line260"></a>  } catch (e) {
<a name="line261"></a>    if (e &amp;&amp; goog.isString(e[&#39;stacktrace&#39;]) &amp;&amp; goog.isString(e[&#39;message&#39;])) {
<a name="line262"></a>      // Remove the stack trace appended to the error message by Opera 10.0
<a name="line263"></a>      var startIndex = e[&#39;message&#39;].length - e[&#39;stacktrace&#39;].length;
<a name="line264"></a>      if (e[&#39;message&#39;].indexOf(e[&#39;stacktrace&#39;], startIndex) == startIndex) {
<a name="line265"></a>        e[&#39;message&#39;] = e[&#39;message&#39;].substr(0, startIndex - 14);
<a name="line266"></a>      }
<a name="line267"></a>    }
<a name="line268"></a>    return e;
<a name="line269"></a>  }
<a name="line270"></a>  goog.testing.asserts.raiseException(comment,
<a name="line271"></a>      &#39;No exception thrown from function passed to assertThrows&#39;);
<a name="line272"></a>};
<a name="line273"></a>
<a name="line274"></a>
<a name="line275"></a>/**
<a name="line276"></a> * Asserts that the function does not throw an error.
<a name="line277"></a> *
<a name="line278"></a> * @param {!(string|Function)} a The assertion comment or the function to call.
<a name="line279"></a> * @param {!Function=} opt_b The function to call (if the first argument of
<a name="line280"></a> *     {@code assertNotThrows} was the comment).
<a name="line281"></a> * @return {*} The return value of the function.
<a name="line282"></a> * @throws {goog.testing.JsUnitException} If the assertion failed.
<a name="line283"></a> */
<a name="line284"></a>var assertNotThrows = function(a, opt_b) {
<a name="line285"></a>  _validateArguments(1, arguments);
<a name="line286"></a>  var comment = commentArg(1, arguments);
<a name="line287"></a>  var func = nonCommentArg(1, 1, arguments);
<a name="line288"></a>  _assert(comment, typeof func == &#39;function&#39;,
<a name="line289"></a>      &#39;Argument passed to assertNotThrows is not a function&#39;);
<a name="line290"></a>
<a name="line291"></a>  try {
<a name="line292"></a>    return func();
<a name="line293"></a>  } catch (e) {
<a name="line294"></a>    comment = comment ? (comment + &#39;\n&#39;) : &#39;&#39;;
<a name="line295"></a>    comment += &#39;A non expected exception was thrown from function passed to &#39; +
<a name="line296"></a>               &#39;assertNotThrows&#39;;
<a name="line297"></a>    // Some browsers don&#39;t have a stack trace so at least have the error
<a name="line298"></a>    // description.
<a name="line299"></a>    var stackTrace = e[&#39;stack&#39;] || e[&#39;stacktrace&#39;] || e.toString();
<a name="line300"></a>    goog.testing.asserts.raiseException(comment, stackTrace);
<a name="line301"></a>  }
<a name="line302"></a>};
<a name="line303"></a>
<a name="line304"></a>
<a name="line305"></a>/**
<a name="line306"></a> * Asserts that the given callback function results in a JsUnitException when
<a name="line307"></a> * called, and that the resulting failure message matches the given expected
<a name="line308"></a> * message.
<a name="line309"></a> * @param {function() : void} callback Function to be run expected to result
<a name="line310"></a> *     in a JsUnitException (usually contains a call to an assert).
<a name="line311"></a> * @param {string=} opt_expectedMessage Failure message expected to be given
<a name="line312"></a> *     with the exception.
<a name="line313"></a> */
<a name="line314"></a>var assertThrowsJsUnitException = function(callback, opt_expectedMessage) {
<a name="line315"></a>  var failed = false;
<a name="line316"></a>  try {
<a name="line317"></a>    goog.testing.asserts.callWithoutLogging(callback);
<a name="line318"></a>  } catch (ex) {
<a name="line319"></a>    if (!ex.isJsUnitException) {
<a name="line320"></a>      fail(&#39;Expected a JsUnitException&#39;);
<a name="line321"></a>    }
<a name="line322"></a>    if (typeof opt_expectedMessage != &#39;undefined&#39; &amp;&amp;
<a name="line323"></a>        ex.message != opt_expectedMessage) {
<a name="line324"></a>      fail(&#39;Expected message [&#39; + opt_expectedMessage + &#39;] but got [&#39; +
<a name="line325"></a>          ex.message + &#39;]&#39;);
<a name="line326"></a>    }
<a name="line327"></a>    failed = true;
<a name="line328"></a>  }
<a name="line329"></a>  if (!failed) {
<a name="line330"></a>    fail(&#39;Expected a failure: &#39; + opt_expectedMessage);
<a name="line331"></a>  }
<a name="line332"></a>};
<a name="line333"></a>
<a name="line334"></a>
<a name="line335"></a>/**
<a name="line336"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line337"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line338"></a> */
<a name="line339"></a>var assertTrue = function(a, opt_b) {
<a name="line340"></a>  _validateArguments(1, arguments);
<a name="line341"></a>  var comment = commentArg(1, arguments);
<a name="line342"></a>  var booleanValue = nonCommentArg(1, 1, arguments);
<a name="line343"></a>
<a name="line344"></a>  _assert(comment, goog.isBoolean(booleanValue),
<a name="line345"></a>      &#39;Bad argument to assertTrue(boolean)&#39;);
<a name="line346"></a>  _assert(comment, booleanValue, &#39;Call to assertTrue(boolean) with false&#39;);
<a name="line347"></a>};
<a name="line348"></a>
<a name="line349"></a>
<a name="line350"></a>/**
<a name="line351"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line352"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line353"></a> */
<a name="line354"></a>var assertFalse = function(a, opt_b) {
<a name="line355"></a>  _validateArguments(1, arguments);
<a name="line356"></a>  var comment = commentArg(1, arguments);
<a name="line357"></a>  var booleanValue = nonCommentArg(1, 1, arguments);
<a name="line358"></a>
<a name="line359"></a>  _assert(comment, goog.isBoolean(booleanValue),
<a name="line360"></a>      &#39;Bad argument to assertFalse(boolean)&#39;);
<a name="line361"></a>  _assert(comment, !booleanValue, &#39;Call to assertFalse(boolean) with true&#39;);
<a name="line362"></a>};
<a name="line363"></a>
<a name="line364"></a>
<a name="line365"></a>/**
<a name="line366"></a> * @param {*} a The expected value (2 args) or the debug message (3 args).
<a name="line367"></a> * @param {*} b The actual value (2 args) or the expected value (3 args).
<a name="line368"></a> * @param {*=} opt_c The actual value (3 args only).
<a name="line369"></a> */
<a name="line370"></a>var assertEquals = function(a, b, opt_c) {
<a name="line371"></a>  _validateArguments(2, arguments);
<a name="line372"></a>  var var1 = nonCommentArg(1, 2, arguments);
<a name="line373"></a>  var var2 = nonCommentArg(2, 2, arguments);
<a name="line374"></a>  _assert(commentArg(2, arguments), var1 === var2,
<a name="line375"></a>          goog.testing.asserts.getDefaultErrorMsg_(var1, var2));
<a name="line376"></a>};
<a name="line377"></a>
<a name="line378"></a>
<a name="line379"></a>/**
<a name="line380"></a> * @param {*} a The expected value (2 args) or the debug message (3 args).
<a name="line381"></a> * @param {*} b The actual value (2 args) or the expected value (3 args).
<a name="line382"></a> * @param {*=} opt_c The actual value (3 args only).
<a name="line383"></a> */
<a name="line384"></a>var assertNotEquals = function(a, b, opt_c) {
<a name="line385"></a>  _validateArguments(2, arguments);
<a name="line386"></a>  var var1 = nonCommentArg(1, 2, arguments);
<a name="line387"></a>  var var2 = nonCommentArg(2, 2, arguments);
<a name="line388"></a>  _assert(commentArg(2, arguments), var1 !== var2,
<a name="line389"></a>      &#39;Expected not to be &#39; + _displayStringForValue(var2));
<a name="line390"></a>};
<a name="line391"></a>
<a name="line392"></a>
<a name="line393"></a>/**
<a name="line394"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line395"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line396"></a> */
<a name="line397"></a>var assertNull = function(a, opt_b) {
<a name="line398"></a>  _validateArguments(1, arguments);
<a name="line399"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line400"></a>  _assert(commentArg(1, arguments), aVar === null,
<a name="line401"></a>      goog.testing.asserts.getDefaultErrorMsg_(null, aVar));
<a name="line402"></a>};
<a name="line403"></a>
<a name="line404"></a>
<a name="line405"></a>/**
<a name="line406"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line407"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line408"></a> */
<a name="line409"></a>var assertNotNull = function(a, opt_b) {
<a name="line410"></a>  _validateArguments(1, arguments);
<a name="line411"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line412"></a>  _assert(commentArg(1, arguments), aVar !== null,
<a name="line413"></a>      &#39;Expected not to be &#39; + _displayStringForValue(null));
<a name="line414"></a>};
<a name="line415"></a>
<a name="line416"></a>
<a name="line417"></a>/**
<a name="line418"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line419"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line420"></a> */
<a name="line421"></a>var assertUndefined = function(a, opt_b) {
<a name="line422"></a>  _validateArguments(1, arguments);
<a name="line423"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line424"></a>  _assert(commentArg(1, arguments), aVar === JSUNIT_UNDEFINED_VALUE,
<a name="line425"></a>      goog.testing.asserts.getDefaultErrorMsg_(JSUNIT_UNDEFINED_VALUE, aVar));
<a name="line426"></a>};
<a name="line427"></a>
<a name="line428"></a>
<a name="line429"></a>/**
<a name="line430"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line431"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line432"></a> */
<a name="line433"></a>var assertNotUndefined = function(a, opt_b) {
<a name="line434"></a>  _validateArguments(1, arguments);
<a name="line435"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line436"></a>  _assert(commentArg(1, arguments), aVar !== JSUNIT_UNDEFINED_VALUE,
<a name="line437"></a>      &#39;Expected not to be &#39; + _displayStringForValue(JSUNIT_UNDEFINED_VALUE));
<a name="line438"></a>};
<a name="line439"></a>
<a name="line440"></a>
<a name="line441"></a>/**
<a name="line442"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line443"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line444"></a> */
<a name="line445"></a>var assertNotNullNorUndefined = function(a, opt_b) {
<a name="line446"></a>  _validateArguments(1, arguments);
<a name="line447"></a>  assertNotNull.apply(null, arguments);
<a name="line448"></a>  assertNotUndefined.apply(null, arguments);
<a name="line449"></a>};
<a name="line450"></a>
<a name="line451"></a>
<a name="line452"></a>/**
<a name="line453"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line454"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line455"></a> */
<a name="line456"></a>var assertNonEmptyString = function(a, opt_b) {
<a name="line457"></a>  _validateArguments(1, arguments);
<a name="line458"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line459"></a>  _assert(commentArg(1, arguments),
<a name="line460"></a>      aVar !== JSUNIT_UNDEFINED_VALUE &amp;&amp; aVar !== null &amp;&amp;
<a name="line461"></a>      typeof aVar == &#39;string&#39; &amp;&amp; aVar !== &#39;&#39;,
<a name="line462"></a>      &#39;Expected non-empty string but was &#39; + _displayStringForValue(aVar));
<a name="line463"></a>};
<a name="line464"></a>
<a name="line465"></a>
<a name="line466"></a>/**
<a name="line467"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line468"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line469"></a> */
<a name="line470"></a>var assertNaN = function(a, opt_b) {
<a name="line471"></a>  _validateArguments(1, arguments);
<a name="line472"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line473"></a>  _assert(commentArg(1, arguments), isNaN(aVar), &#39;Expected NaN&#39;);
<a name="line474"></a>};
<a name="line475"></a>
<a name="line476"></a>
<a name="line477"></a>/**
<a name="line478"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line479"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line480"></a> */
<a name="line481"></a>var assertNotNaN = function(a, opt_b) {
<a name="line482"></a>  _validateArguments(1, arguments);
<a name="line483"></a>  var aVar = nonCommentArg(1, 1, arguments);
<a name="line484"></a>  _assert(commentArg(1, arguments), !isNaN(aVar), &#39;Expected not NaN&#39;);
<a name="line485"></a>};
<a name="line486"></a>
<a name="line487"></a>
<a name="line488"></a>/**
<a name="line489"></a> * Runs a function in an environment where test failures are not logged. This is
<a name="line490"></a> * useful for testing test code, where failures can be a normal part of a test.
<a name="line491"></a> * @param {function() : void} fn Function to run without logging failures.
<a name="line492"></a> */
<a name="line493"></a>goog.testing.asserts.callWithoutLogging = function(fn) {
<a name="line494"></a>  var testRunner = goog.global[&#39;G_testRunner&#39;];
<a name="line495"></a>  var oldLogTestFailure = testRunner[&#39;logTestFailure&#39;];
<a name="line496"></a>  try {
<a name="line497"></a>    // Any failures in the callback shouldn&#39;t be recorded.
<a name="line498"></a>    testRunner[&#39;logTestFailure&#39;] = undefined;
<a name="line499"></a>    fn();
<a name="line500"></a>  } finally {
<a name="line501"></a>    testRunner[&#39;logTestFailure&#39;] = oldLogTestFailure;
<a name="line502"></a>  }
<a name="line503"></a>};
<a name="line504"></a>
<a name="line505"></a>
<a name="line506"></a>/**
<a name="line507"></a> * The return value of the equality predicate passed to findDifferences below,
<a name="line508"></a> * in cases where the predicate can&#39;t test the input variables for equality.
<a name="line509"></a> * @type {?string}
<a name="line510"></a> */
<a name="line511"></a>goog.testing.asserts.EQUALITY_PREDICATE_CANT_PROCESS = null;
<a name="line512"></a>
<a name="line513"></a>
<a name="line514"></a>/**
<a name="line515"></a> * The return value of the equality predicate passed to findDifferences below,
<a name="line516"></a> * in cases where the input vriables are equal.
<a name="line517"></a> * @type {?string}
<a name="line518"></a> */
<a name="line519"></a>goog.testing.asserts.EQUALITY_PREDICATE_VARS_ARE_EQUAL = &#39;&#39;;
<a name="line520"></a>
<a name="line521"></a>
<a name="line522"></a>/**
<a name="line523"></a> * Determines if two items of any type match, and formulates an error message
<a name="line524"></a> * if not.
<a name="line525"></a> * @param {*} expected Expected argument to match.
<a name="line526"></a> * @param {*} actual Argument as a result of performing the test.
<a name="line527"></a> * @param {(function(string, *, *): ?string)=} opt_equalityPredicate An optional
<a name="line528"></a> *     function that can be used to check equality of variables. It accepts 3
<a name="line529"></a> *     arguments: type-of-variables, var1, var2 (in that order) and returns an
<a name="line530"></a> *     error message if the variables are not equal,
<a name="line531"></a> *     goog.testing.asserts.EQUALITY_PREDICATE_VARS_ARE_EQUAL if the variables
<a name="line532"></a> *     are equal, or
<a name="line533"></a> *     goog.testing.asserts.EQUALITY_PREDICATE_CANT_PROCESS if the predicate
<a name="line534"></a> *     couldn&#39;t check the input variables. The function will be called only if
<a name="line535"></a> *     the types of var1 and var2 are identical.
<a name="line536"></a> * @return {?string} Null on success, error message on failure.
<a name="line537"></a> */
<a name="line538"></a>goog.testing.asserts.findDifferences = function(expected, actual,
<a name="line539"></a>    opt_equalityPredicate) {
<a name="line540"></a>  var failures = [];
<a name="line541"></a>  var seen1 = [];
<a name="line542"></a>  var seen2 = [];
<a name="line543"></a>
<a name="line544"></a>  // To avoid infinite recursion when the two parameters are self-referential
<a name="line545"></a>  // along the same path of properties, keep track of the object pairs already
<a name="line546"></a>  // seen in this call subtree, and abort when a cycle is detected.
<a name="line547"></a>  // TODO(gboyer,user): The algorithm still does not terminate in cases
<a name="line548"></a>  // with exponential recursion, e.g. a binary tree with leaf-&gt;root links.
<a name="line549"></a>  // Investigate ways to solve this without significant performance loss
<a name="line550"></a>  // for the common case.
<a name="line551"></a>  function innerAssert(var1, var2, path) {
<a name="line552"></a>    var depth = seen1.length;
<a name="line553"></a>    if (depth % 2) {
<a name="line554"></a>      // Compare with midpoint of seen (&quot;Tortoise and hare&quot; loop detection).
<a name="line555"></a>      // http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare
<a name="line556"></a>      // TODO(gboyer,user): For cases with complex cycles the algorithm
<a name="line557"></a>      // can take a long time to terminate, look into ways to terminate sooner
<a name="line558"></a>      // without adding more than constant-time work in non-cycle cases.
<a name="line559"></a>      var mid = depth &gt;&gt; 1;
<a name="line560"></a>      // Use === to avoid cases like [&#39;x&#39;] == &#39;x&#39;, which is true.
<a name="line561"></a>      var match1 = seen1[mid] === var1;
<a name="line562"></a>      var match2 = seen2[mid] === var2;
<a name="line563"></a>      if (match1 || match2) {
<a name="line564"></a>        if (!match1 || !match2) {
<a name="line565"></a>          // Asymmetric cycles, so the objects have different structure.
<a name="line566"></a>          failures.push(&#39;Asymmetric cycle detected at &#39; + path);
<a name="line567"></a>        }
<a name="line568"></a>        return;
<a name="line569"></a>      }
<a name="line570"></a>    }
<a name="line571"></a>    seen1.push(var1);
<a name="line572"></a>    seen2.push(var2);
<a name="line573"></a>    innerAssert_(var1, var2, path);
<a name="line574"></a>    seen1.pop();
<a name="line575"></a>    seen2.pop();
<a name="line576"></a>  }
<a name="line577"></a>
<a name="line578"></a>  var equalityPredicate = opt_equalityPredicate || function(type, var1, var2) {
<a name="line579"></a>    var typedPredicate = PRIMITIVE_EQUALITY_PREDICATES[type];
<a name="line580"></a>    if (!typedPredicate) {
<a name="line581"></a>      return goog.testing.asserts.EQUALITY_PREDICATE_CANT_PROCESS;
<a name="line582"></a>    }
<a name="line583"></a>    var equal = typedPredicate(var1, var2);
<a name="line584"></a>    return equal ? goog.testing.asserts.EQUALITY_PREDICATE_VARS_ARE_EQUAL :
<a name="line585"></a>        goog.testing.asserts.getDefaultErrorMsg_(var1, var2);
<a name="line586"></a>  };
<a name="line587"></a>
<a name="line588"></a>  /**
<a name="line589"></a>   * @param {*} var1 An item in the expected object.
<a name="line590"></a>   * @param {*} var2 The corresponding item in the actual object.
<a name="line591"></a>   * @param {string} path Their path in the objects.
<a name="line592"></a>   * @suppress {missingProperties} The map_ property is unknown to the compiler
<a name="line593"></a>   *     unless goog.structs.Map is loaded.
<a name="line594"></a>   */
<a name="line595"></a>  function innerAssert_(var1, var2, path) {
<a name="line596"></a>    if (var1 === var2) {
<a name="line597"></a>      return;
<a name="line598"></a>    }
<a name="line599"></a>
<a name="line600"></a>    var typeOfVar1 = _trueTypeOf(var1);
<a name="line601"></a>    var typeOfVar2 = _trueTypeOf(var2);
<a name="line602"></a>
<a name="line603"></a>    if (typeOfVar1 == typeOfVar2) {
<a name="line604"></a>      var isArray = typeOfVar1 == &#39;Array&#39;;
<a name="line605"></a>      var errorMessage = equalityPredicate(typeOfVar1, var1, var2);
<a name="line606"></a>      if (errorMessage !=
<a name="line607"></a>          goog.testing.asserts.EQUALITY_PREDICATE_CANT_PROCESS) {
<a name="line608"></a>        if (errorMessage !=
<a name="line609"></a>            goog.testing.asserts.EQUALITY_PREDICATE_VARS_ARE_EQUAL) {
<a name="line610"></a>          failures.push(path + &#39;: &#39; + errorMessage);
<a name="line611"></a>        }
<a name="line612"></a>      } else if (isArray &amp;&amp; var1.length != var2.length) {
<a name="line613"></a>        failures.push(path + &#39;: Expected &#39; + var1.length + &#39;-element array &#39; +
<a name="line614"></a>                      &#39;but got a &#39; + var2.length + &#39;-element array&#39;);
<a name="line615"></a>      } else {
<a name="line616"></a>        var childPath = path + (isArray ? &#39;[%s]&#39; : (path ? &#39;.%s&#39; : &#39;%s&#39;));
<a name="line617"></a>
<a name="line618"></a>        // if an object has an __iterator__ property, we have no way of
<a name="line619"></a>        // actually inspecting its raw properties, and JS 1.7 doesn&#39;t
<a name="line620"></a>        // overload [] to make it possible for someone to generically
<a name="line621"></a>        // use what the iterator returns to compare the object-managed
<a name="line622"></a>        // properties. This gets us into deep poo with things like
<a name="line623"></a>        // goog.structs.Map, at least on systems that support iteration.
<a name="line624"></a>        if (!var1[&#39;__iterator__&#39;]) {
<a name="line625"></a>          for (var prop in var1) {
<a name="line626"></a>            if (isArray &amp;&amp; goog.testing.asserts.isArrayIndexProp_(prop)) {
<a name="line627"></a>              // Skip array indices for now. We&#39;ll handle them later.
<a name="line628"></a>              continue;
<a name="line629"></a>            }
<a name="line630"></a>
<a name="line631"></a>            if (prop in var2) {
<a name="line632"></a>              innerAssert(var1[prop], var2[prop],
<a name="line633"></a>                          childPath.replace(&#39;%s&#39;, prop));
<a name="line634"></a>            } else {
<a name="line635"></a>              failures.push(&#39;property &#39; + prop +
<a name="line636"></a>                            &#39; not present in actual &#39; + (path || typeOfVar2));
<a name="line637"></a>            }
<a name="line638"></a>          }
<a name="line639"></a>          // make sure there aren&#39;t properties in var2 that are missing
<a name="line640"></a>          // from var1. if there are, then by definition they don&#39;t
<a name="line641"></a>          // match.
<a name="line642"></a>          for (var prop in var2) {
<a name="line643"></a>            if (isArray &amp;&amp; goog.testing.asserts.isArrayIndexProp_(prop)) {
<a name="line644"></a>              // Skip array indices for now. We&#39;ll handle them later.
<a name="line645"></a>              continue;
<a name="line646"></a>            }
<a name="line647"></a>
<a name="line648"></a>            if (!(prop in var1)) {
<a name="line649"></a>              failures.push(&#39;property &#39; + prop +
<a name="line650"></a>                            &#39; not present in expected &#39; +
<a name="line651"></a>                            (path || typeOfVar1));
<a name="line652"></a>            }
<a name="line653"></a>          }
<a name="line654"></a>
<a name="line655"></a>          // Handle array indices by iterating from 0 to arr.length.
<a name="line656"></a>          //
<a name="line657"></a>          // Although all browsers allow holes in arrays, browsers
<a name="line658"></a>          // are inconsistent in what they consider a hole. For example,
<a name="line659"></a>          // &quot;[0,undefined,2]&quot; has a hole on IE but not on Firefox.
<a name="line660"></a>          //
<a name="line661"></a>          // Because our style guide bans for...in iteration over arrays,
<a name="line662"></a>          // we assume that most users don&#39;t care about holes in arrays,
<a name="line663"></a>          // and that it is ok to say that a hole is equivalent to a slot
<a name="line664"></a>          // populated with &#39;undefined&#39;.
<a name="line665"></a>          if (isArray) {
<a name="line666"></a>            for (prop = 0; prop &lt; var1.length; prop++) {
<a name="line667"></a>              innerAssert(var1[prop], var2[prop],
<a name="line668"></a>                          childPath.replace(&#39;%s&#39;, String(prop)));
<a name="line669"></a>            }
<a name="line670"></a>          }
<a name="line671"></a>        } else {
<a name="line672"></a>          // special-case for closure objects that have iterators
<a name="line673"></a>          if (goog.isFunction(var1.equals)) {
<a name="line674"></a>            // use the object&#39;s own equals function, assuming it accepts an
<a name="line675"></a>            // object and returns a boolean
<a name="line676"></a>            if (!var1.equals(var2)) {
<a name="line677"></a>              failures.push(&#39;equals() returned false for &#39; +
<a name="line678"></a>                            (path || typeOfVar1));
<a name="line679"></a>            }
<a name="line680"></a>          } else if (var1.map_) {
<a name="line681"></a>            // assume goog.structs.Map or goog.structs.Set, where comparing
<a name="line682"></a>            // their private map_ field is sufficient
<a name="line683"></a>            innerAssert(var1.map_, var2.map_, childPath.replace(&#39;%s&#39;, &#39;map_&#39;));
<a name="line684"></a>          } else {
<a name="line685"></a>            // else die, so user knows we can&#39;t do anything
<a name="line686"></a>            failures.push(&#39;unable to check &#39; + (path || typeOfVar1) +
<a name="line687"></a>                          &#39; for equality: it has an iterator we do not &#39; +
<a name="line688"></a>                          &#39;know how to handle. please add an equals method&#39;);
<a name="line689"></a>          }
<a name="line690"></a>        }
<a name="line691"></a>      }
<a name="line692"></a>    } else {
<a name="line693"></a>      failures.push(path + &#39; &#39; +
<a name="line694"></a>          goog.testing.asserts.getDefaultErrorMsg_(var1, var2));
<a name="line695"></a>    }
<a name="line696"></a>  }
<a name="line697"></a>
<a name="line698"></a>  innerAssert(expected, actual, &#39;&#39;);
<a name="line699"></a>  return failures.length == 0 ? null :
<a name="line700"></a>      goog.testing.asserts.getDefaultErrorMsg_(expected, actual) +
<a name="line701"></a>          &#39;\n   &#39; + failures.join(&#39;\n   &#39;);
<a name="line702"></a>};
<a name="line703"></a>
<a name="line704"></a>
<a name="line705"></a>/**
<a name="line706"></a> * Notes:
<a name="line707"></a> * Object equality has some nasty browser quirks, and this implementation is
<a name="line708"></a> * not 100% correct. For example,
<a name="line709"></a> *
<a name="line710"></a> * &lt;code&gt;
<a name="line711"></a> * var a = [0, 1, 2];
<a name="line712"></a> * var b = [0, 1, 2];
<a name="line713"></a> * delete a[1];
<a name="line714"></a> * b[1] = undefined;
<a name="line715"></a> * assertObjectEquals(a, b); // should fail, but currently passes
<a name="line716"></a> * &lt;/code&gt;
<a name="line717"></a> *
<a name="line718"></a> * See asserts_test.html for more interesting edge cases.
<a name="line719"></a> *
<a name="line720"></a> * The first comparison object provided is the expected value, the second is
<a name="line721"></a> * the actual.
<a name="line722"></a> *
<a name="line723"></a> * @param {*} a Assertion message or comparison object.
<a name="line724"></a> * @param {*} b Comparison object.
<a name="line725"></a> * @param {*=} opt_c Comparison object, if an assertion message was provided.
<a name="line726"></a> */
<a name="line727"></a>var assertObjectEquals = function(a, b, opt_c) {
<a name="line728"></a>  _validateArguments(2, arguments);
<a name="line729"></a>  var v1 = nonCommentArg(1, 2, arguments);
<a name="line730"></a>  var v2 = nonCommentArg(2, 2, arguments);
<a name="line731"></a>  var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : &#39;&#39;;
<a name="line732"></a>  var differences = goog.testing.asserts.findDifferences(v1, v2);
<a name="line733"></a>
<a name="line734"></a>  _assert(failureMessage, !differences, differences);
<a name="line735"></a>};
<a name="line736"></a>
<a name="line737"></a>
<a name="line738"></a>/**
<a name="line739"></a> * Similar to assertObjectEquals above, but accepts a tolerance margin.
<a name="line740"></a> *
<a name="line741"></a> * @param {*} a Assertion message or comparison object.
<a name="line742"></a> * @param {*} b Comparison object.
<a name="line743"></a> * @param {*} c Comparison object or tolerance.
<a name="line744"></a> * @param {*=} opt_d Tolerance, if an assertion message was provided.
<a name="line745"></a> */
<a name="line746"></a>var assertObjectRoughlyEquals = function(a, b, c, opt_d) {
<a name="line747"></a>  _validateArguments(3, arguments);
<a name="line748"></a>  var v1 = nonCommentArg(1, 3, arguments);
<a name="line749"></a>  var v2 = nonCommentArg(2, 3, arguments);
<a name="line750"></a>  var tolerance = nonCommentArg(3, 3, arguments);
<a name="line751"></a>  var failureMessage = commentArg(3, arguments) ? commentArg(3, arguments) : &#39;&#39;;
<a name="line752"></a>  var equalityPredicate = function(type, var1, var2) {
<a name="line753"></a>    var typedPredicate =
<a name="line754"></a>        goog.testing.asserts.primitiveRoughEqualityPredicates_[type];
<a name="line755"></a>    if (!typedPredicate) {
<a name="line756"></a>      return goog.testing.asserts.EQUALITY_PREDICATE_CANT_PROCESS;
<a name="line757"></a>    }
<a name="line758"></a>    var equal = typedPredicate(var1, var2, tolerance);
<a name="line759"></a>    return equal ? goog.testing.asserts.EQUALITY_PREDICATE_VARS_ARE_EQUAL :
<a name="line760"></a>        goog.testing.asserts.getDefaultErrorMsg_(var1, var2) +
<a name="line761"></a>        &#39; which was more than &#39; + tolerance + &#39; away&#39;;
<a name="line762"></a>  };
<a name="line763"></a>  var differences = goog.testing.asserts.findDifferences(
<a name="line764"></a>      v1, v2, equalityPredicate);
<a name="line765"></a>
<a name="line766"></a>  _assert(failureMessage, !differences, differences);
<a name="line767"></a>};
<a name="line768"></a>
<a name="line769"></a>
<a name="line770"></a>/**
<a name="line771"></a> * Compares two arbitrary objects for non-equalness.
<a name="line772"></a> *
<a name="line773"></a> * All the same caveats as for assertObjectEquals apply here:
<a name="line774"></a> * Undefined values may be confused for missing values, or vice versa.
<a name="line775"></a> *
<a name="line776"></a> * @param {*} a Assertion message or comparison object.
<a name="line777"></a> * @param {*} b Comparison object.
<a name="line778"></a> * @param {*=} opt_c Comparison object, if an assertion message was provided.
<a name="line779"></a> */
<a name="line780"></a>var assertObjectNotEquals = function(a, b, opt_c) {
<a name="line781"></a>  _validateArguments(2, arguments);
<a name="line782"></a>  var v1 = nonCommentArg(1, 2, arguments);
<a name="line783"></a>  var v2 = nonCommentArg(2, 2, arguments);
<a name="line784"></a>  var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : &#39;&#39;;
<a name="line785"></a>  var differences = goog.testing.asserts.findDifferences(v1, v2);
<a name="line786"></a>
<a name="line787"></a>  _assert(failureMessage, differences, &#39;Objects should not be equal&#39;);
<a name="line788"></a>};
<a name="line789"></a>
<a name="line790"></a>
<a name="line791"></a>/**
<a name="line792"></a> * Compares two arrays ignoring negative indexes and extra properties on the
<a name="line793"></a> * array objects. Use case: Internet Explorer adds the index, lastIndex and
<a name="line794"></a> * input enumerable fields to the result of string.match(/regexp/g), which makes
<a name="line795"></a> * assertObjectEquals fail.
<a name="line796"></a> * @param {*} a The expected array (2 args) or the debug message (3 args).
<a name="line797"></a> * @param {*} b The actual array (2 args) or the expected array (3 args).
<a name="line798"></a> * @param {*=} opt_c The actual array (3 args only).
<a name="line799"></a> */
<a name="line800"></a>var assertArrayEquals = function(a, b, opt_c) {
<a name="line801"></a>  _validateArguments(2, arguments);
<a name="line802"></a>  var v1 = nonCommentArg(1, 2, arguments);
<a name="line803"></a>  var v2 = nonCommentArg(2, 2, arguments);
<a name="line804"></a>  var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : &#39;&#39;;
<a name="line805"></a>
<a name="line806"></a>  var typeOfVar1 = _trueTypeOf(v1);
<a name="line807"></a>  _assert(failureMessage,
<a name="line808"></a>          typeOfVar1 == &#39;Array&#39;,
<a name="line809"></a>          &#39;Expected an array for assertArrayEquals but found a &#39; + typeOfVar1);
<a name="line810"></a>
<a name="line811"></a>  var typeOfVar2 = _trueTypeOf(v2);
<a name="line812"></a>  _assert(failureMessage,
<a name="line813"></a>          typeOfVar2 == &#39;Array&#39;,
<a name="line814"></a>          &#39;Expected an array for assertArrayEquals but found a &#39; + typeOfVar2);
<a name="line815"></a>
<a name="line816"></a>  assertObjectEquals(failureMessage,
<a name="line817"></a>      Array.prototype.concat.call(v1), Array.prototype.concat.call(v2));
<a name="line818"></a>};
<a name="line819"></a>
<a name="line820"></a>
<a name="line821"></a>/**
<a name="line822"></a> * Compares two objects that can be accessed like an array and assert that
<a name="line823"></a> * each element is equal.
<a name="line824"></a> * @param {string|Object} a Failure message (3 arguments)
<a name="line825"></a> *     or object #1 (2 arguments).
<a name="line826"></a> * @param {Object} b Object #1 (2 arguments) or object #2 (3 arguments).
<a name="line827"></a> * @param {Object=} c Object #2 (3 arguments).
<a name="line828"></a> */
<a name="line829"></a>var assertElementsEquals = function(a, b, c) {
<a name="line830"></a>  _validateArguments(2, arguments);
<a name="line831"></a>
<a name="line832"></a>  var v1 = nonCommentArg(1, 2, arguments);
<a name="line833"></a>  var v2 = nonCommentArg(2, 2, arguments);
<a name="line834"></a>  var failureMessage = commentArg(2, arguments) ? commentArg(2, arguments) : &#39;&#39;;
<a name="line835"></a>
<a name="line836"></a>  if (!v1) {
<a name="line837"></a>    assert(failureMessage, !v2);
<a name="line838"></a>  } else {
<a name="line839"></a>    assertEquals(&#39;length mismatch: &#39; + failureMessage, v1.length, v2.length);
<a name="line840"></a>    for (var i = 0; i &lt; v1.length; ++i) {
<a name="line841"></a>      assertEquals(
<a name="line842"></a>          &#39;mismatch at index &#39; + i + &#39;: &#39; + failureMessage, v1[i], v2[i]);
<a name="line843"></a>    }
<a name="line844"></a>  }
<a name="line845"></a>};
<a name="line846"></a>
<a name="line847"></a>
<a name="line848"></a>/**
<a name="line849"></a> * Compares two objects that can be accessed like an array and assert that
<a name="line850"></a> * each element is roughly equal.
<a name="line851"></a> * @param {string|Object} a Failure message (4 arguments)
<a name="line852"></a> *     or object #1 (3 arguments).
<a name="line853"></a> * @param {Object} b Object #1 (4 arguments) or object #2 (3 arguments).
<a name="line854"></a> * @param {Object|number} c Object #2 (4 arguments) or tolerance (3 arguments).
<a name="line855"></a> * @param {number=} opt_d tolerance (4 arguments).
<a name="line856"></a> */
<a name="line857"></a>var assertElementsRoughlyEqual = function(a, b, c, opt_d) {
<a name="line858"></a>  _validateArguments(3, arguments);
<a name="line859"></a>
<a name="line860"></a>  var v1 = nonCommentArg(1, 3, arguments);
<a name="line861"></a>  var v2 = nonCommentArg(2, 3, arguments);
<a name="line862"></a>  var tolerance = nonCommentArg(3, 3, arguments);
<a name="line863"></a>  var failureMessage = commentArg(3, arguments) ? commentArg(3, arguments) : &#39;&#39;;
<a name="line864"></a>
<a name="line865"></a>  if (!v1) {
<a name="line866"></a>    assert(failureMessage, !v2);
<a name="line867"></a>  } else {
<a name="line868"></a>    assertEquals(&#39;length mismatch: &#39; + failureMessage, v1.length, v2.length);
<a name="line869"></a>    for (var i = 0; i &lt; v1.length; ++i) {
<a name="line870"></a>      assertRoughlyEquals(failureMessage, v1[i], v2[i], tolerance);
<a name="line871"></a>    }
<a name="line872"></a>  }
<a name="line873"></a>};
<a name="line874"></a>
<a name="line875"></a>
<a name="line876"></a>/**
<a name="line877"></a> * Compares two array-like objects without taking their order into account.
<a name="line878"></a> * @param {string|goog.testing.asserts.ArrayLike} a Assertion message or the
<a name="line879"></a> *     expected elements.
<a name="line880"></a> * @param {goog.testing.asserts.ArrayLike} b Expected elements or the actual
<a name="line881"></a> *     elements.
<a name="line882"></a> * @param {goog.testing.asserts.ArrayLike=} opt_c Actual elements.
<a name="line883"></a> */
<a name="line884"></a>var assertSameElements = function(a, b, opt_c) {
<a name="line885"></a>  _validateArguments(2, arguments);
<a name="line886"></a>  var expected = nonCommentArg(1, 2, arguments);
<a name="line887"></a>  var actual = nonCommentArg(2, 2, arguments);
<a name="line888"></a>  var message = commentArg(2, arguments);
<a name="line889"></a>
<a name="line890"></a>  assertTrue(&#39;Bad arguments to assertSameElements(opt_message, expected: &#39; +
<a name="line891"></a>      &#39;ArrayLike, actual: ArrayLike)&#39;,
<a name="line892"></a>      goog.isArrayLike(expected) &amp;&amp; goog.isArrayLike(actual));
<a name="line893"></a>
<a name="line894"></a>  // Clones expected and actual and converts them to real arrays.
<a name="line895"></a>  expected = goog.testing.asserts.toArray_(expected);
<a name="line896"></a>  actual = goog.testing.asserts.toArray_(actual);
<a name="line897"></a>  // TODO(user): It would be great to show only the difference
<a name="line898"></a>  // between the expected and actual elements.
<a name="line899"></a>  _assert(message, expected.length == actual.length,
<a name="line900"></a>      &#39;Expected &#39; + expected.length + &#39; elements: [&#39; + expected + &#39;], &#39; +
<a name="line901"></a>      &#39;got &#39; + actual.length + &#39; elements: [&#39; + actual + &#39;]&#39;);
<a name="line902"></a>
<a name="line903"></a>  var toFind = goog.testing.asserts.toArray_(expected);
<a name="line904"></a>  for (var i = 0; i &lt; actual.length; i++) {
<a name="line905"></a>    var index = goog.testing.asserts.indexOf_(toFind, actual[i]);
<a name="line906"></a>    _assert(message, index != -1, &#39;Expected [&#39; + expected + &#39;], got [&#39; +
<a name="line907"></a>        actual + &#39;]&#39;);
<a name="line908"></a>    toFind.splice(index, 1);
<a name="line909"></a>  }
<a name="line910"></a>};
<a name="line911"></a>
<a name="line912"></a>
<a name="line913"></a>/**
<a name="line914"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line915"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line916"></a> */
<a name="line917"></a>var assertEvaluatesToTrue = function(a, opt_b) {
<a name="line918"></a>  _validateArguments(1, arguments);
<a name="line919"></a>  var value = nonCommentArg(1, 1, arguments);
<a name="line920"></a>  if (!value) {
<a name="line921"></a>    _assert(commentArg(1, arguments), false, &#39;Expected to evaluate to true&#39;);
<a name="line922"></a>  }
<a name="line923"></a>};
<a name="line924"></a>
<a name="line925"></a>
<a name="line926"></a>/**
<a name="line927"></a> * @param {*} a The value to assert (1 arg) or debug message (2 args).
<a name="line928"></a> * @param {*=} opt_b The value to assert (2 args only).
<a name="line929"></a> */
<a name="line930"></a>var assertEvaluatesToFalse = function(a, opt_b) {
<a name="line931"></a>  _validateArguments(1, arguments);
<a name="line932"></a>  var value = nonCommentArg(1, 1, arguments);
<a name="line933"></a>  if (value) {
<a name="line934"></a>    _assert(commentArg(1, arguments), false, &#39;Expected to evaluate to false&#39;);
<a name="line935"></a>  }
<a name="line936"></a>};
<a name="line937"></a>
<a name="line938"></a>
<a name="line939"></a>/**
<a name="line940"></a> * Compares two HTML snippets.
<a name="line941"></a> *
<a name="line942"></a> * Take extra care if attributes are involved. {@code assertHTMLEquals}&#39;s
<a name="line943"></a> * implementation isn&#39;t prepared for complex cases. For example, the following
<a name="line944"></a> * comparisons erroneously fail:
<a name="line945"></a> * &lt;pre&gt;
<a name="line946"></a> * assertHTMLEquals(&#39;&lt;a href=&quot;x&quot; target=&quot;y&quot;&gt;&#39;, &#39;&lt;a target=&quot;y&quot; href=&quot;x&quot;&gt;&#39;);
<a name="line947"></a> * assertHTMLEquals(&#39;&lt;div classname=&quot;a b&quot;&gt;&#39;, &#39;&lt;div classname=&quot;b a&quot;&gt;&#39;);
<a name="line948"></a> * assertHTMLEquals(&#39;&lt;input disabled&gt;&#39;, &#39;&lt;input disabled=&quot;disabled&quot;&gt;&#39;);
<a name="line949"></a> * &lt;/pre&gt;
<a name="line950"></a> *
<a name="line951"></a> * When in doubt, use {@code goog.testing.dom.assertHtmlMatches}.
<a name="line952"></a> *
<a name="line953"></a> * @param {*} a The expected value (2 args) or the debug message (3 args).
<a name="line954"></a> * @param {*} b The actual value (2 args) or the expected value (3 args).
<a name="line955"></a> * @param {*=} opt_c The actual value (3 args only).
<a name="line956"></a> */
<a name="line957"></a>var assertHTMLEquals = function(a, b, opt_c) {
<a name="line958"></a>  _validateArguments(2, arguments);
<a name="line959"></a>  var var1 = nonCommentArg(1, 2, arguments);
<a name="line960"></a>  var var2 = nonCommentArg(2, 2, arguments);
<a name="line961"></a>  var var1Standardized = standardizeHTML(var1);
<a name="line962"></a>  var var2Standardized = standardizeHTML(var2);
<a name="line963"></a>
<a name="line964"></a>  _assert(commentArg(2, arguments), var1Standardized === var2Standardized,
<a name="line965"></a>          goog.testing.asserts.getDefaultErrorMsg_(
<a name="line966"></a>              var1Standardized, var2Standardized));
<a name="line967"></a>};
<a name="line968"></a>
<a name="line969"></a>
<a name="line970"></a>/**
<a name="line971"></a> * Compares two CSS property values to make sure that they represent the same
<a name="line972"></a> * things. This will normalize values in the browser. For example, in Firefox,
<a name="line973"></a> * this assertion will consider &quot;rgb(0, 0, 255)&quot; and &quot;#0000ff&quot; to be identical
<a name="line974"></a> * values for the &quot;color&quot; property. This function won&#39;t normalize everything --
<a name="line975"></a> * for example, in most browsers, &quot;blue&quot; will not match &quot;#0000ff&quot;. It is
<a name="line976"></a> * intended only to compensate for unexpected normalizations performed by
<a name="line977"></a> * the browser that should also affect your expected value.
<a name="line978"></a> * @param {string} a Assertion message, or the CSS property name.
<a name="line979"></a> * @param {string} b CSS property name, or the expected value.
<a name="line980"></a> * @param {string} c The expected value, or the actual value.
<a name="line981"></a> * @param {string=} opt_d The actual value.
<a name="line982"></a> */
<a name="line983"></a>var assertCSSValueEquals = function(a, b, c, opt_d) {
<a name="line984"></a>  _validateArguments(3, arguments);
<a name="line985"></a>  var propertyName = nonCommentArg(1, 3, arguments);
<a name="line986"></a>  var expectedValue = nonCommentArg(2, 3, arguments);
<a name="line987"></a>  var actualValue = nonCommentArg(3, 3, arguments);
<a name="line988"></a>  var expectedValueStandardized =
<a name="line989"></a>      standardizeCSSValue(propertyName, expectedValue);
<a name="line990"></a>  var actualValueStandardized =
<a name="line991"></a>      standardizeCSSValue(propertyName, actualValue);
<a name="line992"></a>
<a name="line993"></a>  _assert(commentArg(3, arguments),
<a name="line994"></a>          expectedValueStandardized == actualValueStandardized,
<a name="line995"></a>          goog.testing.asserts.getDefaultErrorMsg_(
<a name="line996"></a>              expectedValueStandardized, actualValueStandardized));
<a name="line997"></a>};
<a name="line998"></a>
<a name="line999"></a>
<a name="line1000"></a>/**
<a name="line1001"></a> * @param {*} a The expected value (2 args) or the debug message (3 args).
<a name="line1002"></a> * @param {*} b The actual value (2 args) or the expected value (3 args).
<a name="line1003"></a> * @param {*=} opt_c The actual value (3 args only).
<a name="line1004"></a> */
<a name="line1005"></a>var assertHashEquals = function(a, b, opt_c) {
<a name="line1006"></a>  _validateArguments(2, arguments);
<a name="line1007"></a>  var var1 = nonCommentArg(1, 2, arguments);
<a name="line1008"></a>  var var2 = nonCommentArg(2, 2, arguments);
<a name="line1009"></a>  var message = commentArg(2, arguments);
<a name="line1010"></a>  for (var key in var1) {
<a name="line1011"></a>    _assert(message,
<a name="line1012"></a>        key in var2, &#39;Expected hash had key &#39; + key + &#39; that was not found&#39;);
<a name="line1013"></a>    _assert(message, var1[key] == var2[key], &#39;Value for key &#39; + key +
<a name="line1014"></a>        &#39; mismatch - expected = &#39; + var1[key] + &#39;, actual = &#39; + var2[key]);
<a name="line1015"></a>  }
<a name="line1016"></a>
<a name="line1017"></a>  for (var key in var2) {
<a name="line1018"></a>    _assert(message, key in var1, &#39;Actual hash had key &#39; + key +
<a name="line1019"></a>        &#39; that was not expected&#39;);
<a name="line1020"></a>  }
<a name="line1021"></a>};
<a name="line1022"></a>
<a name="line1023"></a>
<a name="line1024"></a>/**
<a name="line1025"></a> * @param {*} a The expected value (3 args) or the debug message (4 args).
<a name="line1026"></a> * @param {*} b The actual value (3 args) or the expected value (4 args).
<a name="line1027"></a> * @param {*} c The tolerance (3 args) or the actual value (4 args).
<a name="line1028"></a> * @param {*=} opt_d The tolerance (4 args only).
<a name="line1029"></a> */
<a name="line1030"></a>var assertRoughlyEquals = function(a, b, c, opt_d) {
<a name="line1031"></a>  _validateArguments(3, arguments);
<a name="line1032"></a>  var expected = nonCommentArg(1, 3, arguments);
<a name="line1033"></a>  var actual = nonCommentArg(2, 3, arguments);
<a name="line1034"></a>  var tolerance = nonCommentArg(3, 3, arguments);
<a name="line1035"></a>  _assert(commentArg(3, arguments),
<a name="line1036"></a>      goog.testing.asserts.numberRoughEqualityPredicate_(
<a name="line1037"></a>          expected, actual, tolerance),
<a name="line1038"></a>      &#39;Expected &#39; + expected + &#39;, but got &#39; + actual +
<a name="line1039"></a>      &#39; which was more than &#39; + tolerance + &#39; away&#39;);
<a name="line1040"></a>};
<a name="line1041"></a>
<a name="line1042"></a>
<a name="line1043"></a>/**
<a name="line1044"></a> * Checks if the given element is the member of the given container.
<a name="line1045"></a> * @param {*} a Failure message (3 arguments) or the contained element
<a name="line1046"></a> *     (2 arguments).
<a name="line1047"></a> * @param {*} b The contained element (3 arguments) or the container
<a name="line1048"></a> *     (2 arguments).
<a name="line1049"></a> * @param {*=} opt_c The container.
<a name="line1050"></a> */
<a name="line1051"></a>var assertContains = function(a, b, opt_c) {
<a name="line1052"></a>  _validateArguments(2, arguments);
<a name="line1053"></a>  var contained = nonCommentArg(1, 2, arguments);
<a name="line1054"></a>  var container = nonCommentArg(2, 2, arguments);
<a name="line1055"></a>  _assert(commentArg(2, arguments),
<a name="line1056"></a>      goog.testing.asserts.contains_(container, contained),
<a name="line1057"></a>      &#39;Expected \&#39;&#39; + container + &#39;\&#39; to contain \&#39;&#39; + contained + &#39;\&#39;&#39;);
<a name="line1058"></a>};
<a name="line1059"></a>
<a name="line1060"></a>
<a name="line1061"></a>/**
<a name="line1062"></a> * Checks if the given element is not the member of the given container.
<a name="line1063"></a> * @param {*} a Failure message (3 arguments) or the contained element
<a name="line1064"></a> *     (2 arguments).
<a name="line1065"></a> * @param {*} b The contained element (3 arguments) or the container
<a name="line1066"></a> *     (2 arguments).
<a name="line1067"></a> * @param {*=} opt_c The container.
<a name="line1068"></a> */
<a name="line1069"></a>var assertNotContains = function(a, b, opt_c) {
<a name="line1070"></a>  _validateArguments(2, arguments);
<a name="line1071"></a>  var contained = nonCommentArg(1, 2, arguments);
<a name="line1072"></a>  var container = nonCommentArg(2, 2, arguments);
<a name="line1073"></a>  _assert(commentArg(2, arguments),
<a name="line1074"></a>      !goog.testing.asserts.contains_(container, contained),
<a name="line1075"></a>      &#39;Expected \&#39;&#39; + container + &#39;\&#39; not to contain \&#39;&#39; + contained + &#39;\&#39;&#39;);
<a name="line1076"></a>};
<a name="line1077"></a>
<a name="line1078"></a>
<a name="line1079"></a>/**
<a name="line1080"></a> * Converts an array like object to array or clones it if it&#39;s already array.
<a name="line1081"></a> * @param {goog.testing.asserts.ArrayLike} arrayLike The collection.
<a name="line1082"></a> * @return {!Array} Copy of the collection as array.
<a name="line1083"></a> * @private
<a name="line1084"></a> */
<a name="line1085"></a>goog.testing.asserts.toArray_ = function(arrayLike) {
<a name="line1086"></a>  var ret = [];
<a name="line1087"></a>  for (var i = 0; i &lt; arrayLike.length; i++) {
<a name="line1088"></a>    ret[i] = arrayLike[i];
<a name="line1089"></a>  }
<a name="line1090"></a>  return ret;
<a name="line1091"></a>};
<a name="line1092"></a>
<a name="line1093"></a>
<a name="line1094"></a>/**
<a name="line1095"></a> * Finds the position of the first occurrence of an element in a container.
<a name="line1096"></a> * @param {goog.testing.asserts.ArrayLike} container
<a name="line1097"></a> *     The array to find the element in.
<a name="line1098"></a> * @param {*} contained Element to find.
<a name="line1099"></a> * @return {number} Index of the first occurrence or -1 if not found.
<a name="line1100"></a> * @private
<a name="line1101"></a> */
<a name="line1102"></a>goog.testing.asserts.indexOf_ = function(container, contained) {
<a name="line1103"></a>  if (container.indexOf) {
<a name="line1104"></a>    return container.indexOf(contained);
<a name="line1105"></a>  } else {
<a name="line1106"></a>    // IE6/7 do not have indexOf so do a search.
<a name="line1107"></a>    for (var i = 0; i &lt; container.length; i++) {
<a name="line1108"></a>      if (container[i] === contained) {
<a name="line1109"></a>        return i;
<a name="line1110"></a>      }
<a name="line1111"></a>    }
<a name="line1112"></a>    return -1;
<a name="line1113"></a>  }
<a name="line1114"></a>};
<a name="line1115"></a>
<a name="line1116"></a>
<a name="line1117"></a>/**
<a name="line1118"></a> * Tells whether the array contains the given element.
<a name="line1119"></a> * @param {goog.testing.asserts.ArrayLike} container The array to
<a name="line1120"></a> *     find the element in.
<a name="line1121"></a> * @param {*} contained Element to find.
<a name="line1122"></a> * @return {boolean} Whether the element is in the array.
<a name="line1123"></a> * @private
<a name="line1124"></a> */
<a name="line1125"></a>goog.testing.asserts.contains_ = function(container, contained) {
<a name="line1126"></a>  // TODO(user): Can we check for container.contains as well?
<a name="line1127"></a>  // That would give us support for most goog.structs (though weird results
<a name="line1128"></a>  // with anything else with a contains method, like goog.math.Range). Falling
<a name="line1129"></a>  // back with container.some would catch all iterables, too.
<a name="line1130"></a>  return goog.testing.asserts.indexOf_(container, contained) != -1;
<a name="line1131"></a>};
<a name="line1132"></a>
<a name="line1133"></a>var standardizeHTML = function(html) {
<a name="line1134"></a>  var translator = document.createElement(&#39;DIV&#39;);
<a name="line1135"></a>  translator.innerHTML = html;
<a name="line1136"></a>
<a name="line1137"></a>  // Trim whitespace from result (without relying on goog.string)
<a name="line1138"></a>  return translator.innerHTML.replace(/^\s+|\s+$/g, &#39;&#39;);
<a name="line1139"></a>};
<a name="line1140"></a>
<a name="line1141"></a>
<a name="line1142"></a>/**
<a name="line1143"></a> * Standardizes a CSS value for a given property by applying it to an element
<a name="line1144"></a> * and then reading it back.
<a name="line1145"></a> * @param {string} propertyName CSS property name.
<a name="line1146"></a> * @param {string} value CSS value.
<a name="line1147"></a> * @return {string} Normalized CSS value.
<a name="line1148"></a> */
<a name="line1149"></a>var standardizeCSSValue = function(propertyName, value) {
<a name="line1150"></a>  var styleDeclaration = document.createElement(&#39;DIV&#39;).style;
<a name="line1151"></a>  styleDeclaration[propertyName] = value;
<a name="line1152"></a>  return styleDeclaration[propertyName];
<a name="line1153"></a>};
<a name="line1154"></a>
<a name="line1155"></a>
<a name="line1156"></a>/**
<a name="line1157"></a> * Raises a JsUnit exception with the given comment.
<a name="line1158"></a> * @param {string} comment A summary for the exception.
<a name="line1159"></a> * @param {string=} opt_message A description of the exception.
<a name="line1160"></a> */
<a name="line1161"></a>goog.testing.asserts.raiseException = function(comment, opt_message) {
<a name="line1162"></a>  if (goog.global[&#39;CLOSURE_INSPECTOR___&#39;] &amp;&amp;
<a name="line1163"></a>      goog.global[&#39;CLOSURE_INSPECTOR___&#39;][&#39;supportsJSUnit&#39;]) {
<a name="line1164"></a>    goog.global[&#39;CLOSURE_INSPECTOR___&#39;][&#39;jsUnitFailure&#39;](comment, opt_message);
<a name="line1165"></a>  }
<a name="line1166"></a>
<a name="line1167"></a>  throw new goog.testing.JsUnitException(comment, opt_message);
<a name="line1168"></a>};
<a name="line1169"></a>
<a name="line1170"></a>
<a name="line1171"></a>/**
<a name="line1172"></a> * Helper function for assertObjectEquals.
<a name="line1173"></a> * @param {string} prop A property name.
<a name="line1174"></a> * @return {boolean} If the property name is an array index.
<a name="line1175"></a> * @private
<a name="line1176"></a> */
<a name="line1177"></a>goog.testing.asserts.isArrayIndexProp_ = function(prop) {
<a name="line1178"></a>  return (prop | 0) == prop;
<a name="line1179"></a>};
<a name="line1180"></a>
<a name="line1181"></a>
<a name="line1182"></a>
<a name="line1183"></a>/**
<a name="line1184"></a> * @param {string} comment A summary for the exception.
<a name="line1185"></a> * @param {?string=} opt_message A description of the exception.
<a name="line1186"></a> * @constructor
<a name="line1187"></a> */
<a name="line1188"></a>goog.testing.JsUnitException = function(comment, opt_message) {
<a name="line1189"></a>  this.isJsUnitException = true;
<a name="line1190"></a>  this.message = (comment ? comment : &#39;&#39;) +
<a name="line1191"></a>                 (comment &amp;&amp; opt_message ? &#39;\n&#39; : &#39;&#39;) +
<a name="line1192"></a>                 (opt_message ? opt_message : &#39;&#39;);
<a name="line1193"></a>  this.stackTrace = goog.testing.stacktrace.get();
<a name="line1194"></a>  // These fields are for compatibility with jsUnitTestManager.
<a name="line1195"></a>  this.comment = comment || null;
<a name="line1196"></a>  this.jsUnitMessage = opt_message || &#39;&#39;;
<a name="line1197"></a>};
<a name="line1198"></a>
<a name="line1199"></a>
<a name="line1200"></a>/** @override */
<a name="line1201"></a>goog.testing.JsUnitException.prototype.toString = function() {
<a name="line1202"></a>  return this.message;
<a name="line1203"></a>};
<a name="line1204"></a>
<a name="line1205"></a>
<a name="line1206"></a>goog.exportSymbol(&#39;fail&#39;, fail);
<a name="line1207"></a>goog.exportSymbol(&#39;assert&#39;, assert);
<a name="line1208"></a>goog.exportSymbol(&#39;assertThrows&#39;, assertThrows);
<a name="line1209"></a>goog.exportSymbol(&#39;assertNotThrows&#39;, assertNotThrows);
<a name="line1210"></a>goog.exportSymbol(&#39;assertTrue&#39;, assertTrue);
<a name="line1211"></a>goog.exportSymbol(&#39;assertFalse&#39;, assertFalse);
<a name="line1212"></a>goog.exportSymbol(&#39;assertEquals&#39;, assertEquals);
<a name="line1213"></a>goog.exportSymbol(&#39;assertNotEquals&#39;, assertNotEquals);
<a name="line1214"></a>goog.exportSymbol(&#39;assertNull&#39;, assertNull);
<a name="line1215"></a>goog.exportSymbol(&#39;assertNotNull&#39;, assertNotNull);
<a name="line1216"></a>goog.exportSymbol(&#39;assertUndefined&#39;, assertUndefined);
<a name="line1217"></a>goog.exportSymbol(&#39;assertNotUndefined&#39;, assertNotUndefined);
<a name="line1218"></a>goog.exportSymbol(&#39;assertNotNullNorUndefined&#39;, assertNotNullNorUndefined);
<a name="line1219"></a>goog.exportSymbol(&#39;assertNonEmptyString&#39;, assertNonEmptyString);
<a name="line1220"></a>goog.exportSymbol(&#39;assertNaN&#39;, assertNaN);
<a name="line1221"></a>goog.exportSymbol(&#39;assertNotNaN&#39;, assertNotNaN);
<a name="line1222"></a>goog.exportSymbol(&#39;assertObjectEquals&#39;, assertObjectEquals);
<a name="line1223"></a>goog.exportSymbol(&#39;assertObjectRoughlyEquals&#39;, assertObjectRoughlyEquals);
<a name="line1224"></a>goog.exportSymbol(&#39;assertObjectNotEquals&#39;, assertObjectNotEquals);
<a name="line1225"></a>goog.exportSymbol(&#39;assertArrayEquals&#39;, assertArrayEquals);
<a name="line1226"></a>goog.exportSymbol(&#39;assertElementsEquals&#39;, assertElementsEquals);
<a name="line1227"></a>goog.exportSymbol(&#39;assertElementsRoughlyEqual&#39;, assertElementsRoughlyEqual);
<a name="line1228"></a>goog.exportSymbol(&#39;assertSameElements&#39;, assertSameElements);
<a name="line1229"></a>goog.exportSymbol(&#39;assertEvaluatesToTrue&#39;, assertEvaluatesToTrue);
<a name="line1230"></a>goog.exportSymbol(&#39;assertEvaluatesToFalse&#39;, assertEvaluatesToFalse);
<a name="line1231"></a>goog.exportSymbol(&#39;assertHTMLEquals&#39;, assertHTMLEquals);
<a name="line1232"></a>goog.exportSymbol(&#39;assertHashEquals&#39;, assertHashEquals);
<a name="line1233"></a>goog.exportSymbol(&#39;assertRoughlyEquals&#39;, assertRoughlyEquals);
<a name="line1234"></a>goog.exportSymbol(&#39;assertContains&#39;, assertContains);
<a name="line1235"></a>goog.exportSymbol(&#39;assertNotContains&#39;, assertNotContains);
</pre>


</body>
</html>
